package com.example.yang.ministy;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by Yang on 2016/9/12.
 */
public class AppSharedPrefs {
    private static final String SHARED_PREFS_NAME="app_shared_prefs";
    private static final String KEY_IS_FIRST_RUN="is_first_run";
    private static final String KEY_ACCOUNT="account";
    private static final String KEY_PASSWD="passwd";
    private SharedPreferences mq;
   private SharedPreferences.Editor editor;
    private  static AppSharedPrefs it;
    public AppSharedPrefs(Context context){
         mq=context.getSharedPreferences(SHARED_PREFS_NAME,Context.MODE_PRIVATE);
        editor=mq.edit();

    }
    public boolean getIsFirstRun(){
        return mq.getBoolean(KEY_IS_FIRST_RUN,true);
    }
    public String getAccount(String defAcount){
        return mq.getString(KEY_ACCOUNT,defAcount);
    }
    public String getPasswd(String defPasswd){
        return mq.getString(KEY_PASSWD,defPasswd);
    }
    public void SetisFirstRun(boolean firstRun){
        editor.putBoolean(KEY_IS_FIRST_RUN,firstRun);
        editor.commit();
    }
    public void SetAccount(String account){
        editor.putString(KEY_ACCOUNT,account);
        editor.commit();
    }
    public void SetPasswd(String passwd){
        editor.putString(KEY_IS_FIRST_RUN,passwd);
        editor.commit();
    }


    public static synchronized AppSharedPrefs getInstance(Context context){
        if (it==null) it=new AppSharedPrefs(context);
        return it;

    }
}
